from flask import Flask, render_template, request, redirect, url_for

app = Flask(__name__)

# 假设的用户信息，实际中你可以从数据库中获取
users = {
    "user1": "ls",
    "user2": "password2"
}

# 首页：显示伪装的登录页面
@app.route('/')
def home():
    return render_template('login.html')

# 登录验证路由
@app.route('/login', methods=['POST'])
def login():
    username = request.form['username']
    password = request.form['password']
    
    # 简单的用户名和密码验证
    if users.get(username) == password:
        return redirect(url_for('chat'))
    else:
        return "登录失败，用户名或密码错误！", 401

# 聊天页面
@app.route('/chat')
def chat():
    return render_template('chat.html')

if __name__ == '__main__':
    app.run(ssl_context='adhoc', debug=True)  # 启动时自动生成SSL证书
